package org.craftedsw.tripservicekata.trip;

import java.util.ArrayList;
import java.util.List;

import org.craftedsw.tripservicekata.exception.UserNotLoggedInException;
import org.craftedsw.tripservicekata.user.User;

public class TripService {
	
	private TripDAO tripDao;
	
	public TripService(TripDAO tripDao) {
		this.tripDao = tripDao;
	}

	public List<Trip> getTripsByUser(User traveler, User loggedUser) {
		if (loggedUser == null) {
			throw new UserNotLoggedInException();
		} 
		return (traveler.isFriend(loggedUser)) ? tripDao.instanceOfFindTripsByUser(traveler)
					: new ArrayList<Trip>();
	}
}
